﻿using System;
using System.Collections.Generic;
 
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using ExtAspNet;
using System.Text;

namespace HY.WEB.SA
{
    public partial class jobpubview : PageBase
    {

        public string whe = "";
        public string us,um,ubh;
        public string tab = "comp_job";

        protected void Page_Load(object sender, EventArgs e)
        {
            us = Session["ID"].ToString();
            um = Session["user"].ToString();
            ubh = Session["bh"].ToString();
        
            if (!IsPostBack)
            {


             //   btnDelete.OnClientClick = Grid1.GetNoSelectionAlertReference("至少选择一项！");
             //   btnNew.OnClientClick = Window1.GetSaveStateReference(hidstype.ClientID)
//+Window1.GetShowReference("work_add.aspx?stype=" + stype + "", "新增");
               //  btnSearch.OnClientClick =  Window1.GetShowReference("../function/search.aspx?tab="+tab+"", "高级搜索");
      
                BindGrid();
                fill(); //填充查询
                
            }

        }


        void fill()
        {

            //公司分类
            DataTable e = BLL.Bllbase.get_table("[company]");
            ddlcompany.Items.Clear();
            for (int i = 0; i < e.Rows.Count; i++)
            {
                ddlcompany.Items.Add(new ExtAspNet.ListItem(e.Rows[i]["cname"].ToString().Trim(), e.Rows[i]["cbh"].ToString().Trim()));
            }
            ddlcompany.DataBind();
            ddlcompany.Items.Add(new ExtAspNet.ListItem(" ", " "));
            ddlcompany.SelectedIndex = ddlcompany.Items.IndexOf(ddlcompany.Items.FindByValue(" "));

            //if (hidcomp.Text != "")     //最公司      
            //    ddlcompany.SelectedIndex = ddlcompany.Items.IndexOf(ddlcompany.Items.FindByValue(hidcomp.Text));





            //岗位分类
            e = BLL.Bllbase.get_table("[pub_cate]");
            //  e = BLL.Bllbase.get_table("[pub_cate_sub]", " right(rtrim(scode)='00'");
            ddlgw.Items.Clear();
            for (int i = 0; i < e.Rows.Count; i++)
            {
                ddlgw.Items.Add(new ExtAspNet.ListItem(e.Rows[i]["svalue"].ToString().Trim(), e.Rows[i]["scode"].ToString().Trim()));
            }
            ddlgw.DataBind();
            ddlgw.Items.Add(new ExtAspNet.ListItem(" ", " "));
            ddlgw.SelectedIndex = ddlgw.Items.IndexOf(ddlgw.Items.FindByValue(" "));

            ddlgwsub.Items.Add(new ExtAspNet.ListItem(" ", " "));


            //工作地点
            e = BLL.Bllbase.get_table("[pub_area]");
            ddlSheng.Items.Clear();
            for (int i = 0; i < e.Rows.Count; i++)
            {
                ddlSheng.Items.Add(new ExtAspNet.ListItem(e.Rows[i]["svalue"].ToString().Trim(), e.Rows[i]["scode"].ToString().Trim()));
            }
            ddlSheng.DataBind();

            ddlSheng.Items.Add(new ExtAspNet.ListItem(" ", " "));
            ddlSheng.SelectedIndex = ddlSheng.Items.IndexOf(ddlSheng.Items.FindByValue(" "));

            //ddlShi.Items.Add(new ExtAspNet.ListItem("东莞", "103002"));
            ddlShi.Items.Add(new ExtAspNet.ListItem(" ", " "));

            //镇区
            e = BLL.Bllbase.get_table("[pub_zone]");
            ddlzone.Items.Clear();
            for (int i = 0; i < e.Rows.Count; i++)
            {
                ddlzone.Items.Add(new ExtAspNet.ListItem(e.Rows[i]["svalue"].ToString().Trim(), e.Rows[i]["scode"].ToString().Trim()));
            }
            ddlzone.DataBind();
            ddlzone.Items.Add(new ExtAspNet.ListItem(" ", " "));
            ddlzone.SelectedIndex = ddlzone.Items.IndexOf(ddlzone.Items.FindByValue(" "));

            //学历
            e = BLL.Bllbase.get_table("[sys_edu]");
            ddledu.Items.Clear();
            for (int i = 0; i < e.Rows.Count; i++)
            {
                ddledu.Items.Add(new ExtAspNet.ListItem(e.Rows[i]["edu_nm"].ToString().Trim(), e.Rows[i]["edu_nm"].ToString().Trim()));
            }
            ddledu.DataBind();
            ddledu.Items.Add(new ExtAspNet.ListItem(" ", " "));
            ddledu.SelectedIndex = ddledu.Items.IndexOf(ddledu.Items.FindByValue(" "));

            //date1.Text = DateTime.Now.ToString("yyyy-MM-dd");

            // date2.Text = DateTime.Now.AddDays(30).ToString("yyyy-MM-dd");

        }


        private void BindGrid()
        {
            DataTable table;
            

            table = BLL.Bllbase.get_table(tab,whe);
            DataView view1 = table.DefaultView;
            view1.Sort = String.Format("{0} {1}", " sid ", " desc");

            Grid1.DataSource = table;
            Grid1.DataBind();

        }


        protected void Grid1_PageIndexChange(object sender, ExtAspNet.GridPageEventArgs e)
        {
            Grid1.PageIndex = e.NewPageIndex;
        }



        protected void Grid1_Sort(object sender, ExtAspNet.GridSortEventArgs e)
        {
              DataTable table;

            table = BLL.Bllbase.get_table(tab, whe);

            DataView view1 = table.DefaultView;
            view1.Sort = String.Format("{0} {1}", e.SortField, e.SortDirection);

            Grid1.DataSource = view1;
            Grid1.DataBind();
        }


        //取城市
        public static string getzone(string val)
        {
            DataTable dte = BLL.Bllbase.get_table("[pub_zone]", " scode='" + val + "' ");
            if (dte.Rows.Count > 0)
                return dte.Rows[0]["svalue"].ToString();
            else
                return "";

        }





        protected void ddlSheng_SelectedIndexChanged(object sender, EventArgs e)
        {
            ddlShi.Items.Clear();
            BindShi();
        }



        private void BindShi()
        {
            string sheng = ddlSheng.SelectedValue;
            //工作地点
            DataTable e = BLL.Bllbase.get_table("[pub_area_sub]", "left(scode,4)='" + sheng + "'");
            ddlShi.Items.Clear();
            for (int i = 0; i < e.Rows.Count; i++)
            {
                ddlShi.Items.Add(new ExtAspNet.ListItem(e.Rows[i]["svalue"].ToString().Trim(), e.Rows[i]["scode"].ToString().Trim()));
            }
            ddlShi.DataBind();


            //  ddlShi.Items.Insert(0, new ListItem("选择地区市", "-1"));
        }

        protected void ddlgw_SelectedIndexChanged(object sender, EventArgs e)
        {
            ddlgwsub.Items.Clear();
            BindGW();
        }

        protected void Window1_Close(object sender, EventArgs e)
        {
            // Alert.ShowInTop("弹出窗口关闭了！");
            // string key = txt.Text.Trim();
            string key = "";
            // stype = hidstype.Text;
            try
            {
                if (key == "") whe = whe + " and " + BLL.pub.pubwhere.get_where_sql(us, tab);
                BindGrid();

            }
            catch (Exception ex)
            {
                //   Alert.Show("查询条件错误");
            }
            finally
            {
                whe = "";
                // whe = " cbh in (select cbh from company_fav where sbh='" + bh + "')";
            }
            BindGrid();
        }

        private void BindGW()
        {
            string gw = ddlgw.SelectedValue.Trim();
            gw = gw.Substring(0, 2);
            //工作地点
            DataTable e = BLL.Bllbase.get_table("pub_cate_sub", "left(scode,2)='" + gw + "'");
            ddlgwsub.Items.Clear();
            for (int i = 0; i < e.Rows.Count; i++)
            {
                ddlgwsub.Items.Add(new ExtAspNet.ListItem(e.Rows[i]["svalue"].ToString(), e.Rows[i]["scode"].ToString()));
            }
            ddlgwsub.DataBind();
            //  ddlShi.Items.Insert(0, new ListItem("选择地区市", "-1"));
        }

        protected void btsearch_Click(object sender, EventArgs e)
        {
            string key = txtjob.Text; //关键字或岗们名称
            string cbh = ddlcompany.SelectedValue.Trim();
            string gw = ddlgw.SelectedValue.Trim();
            string gws = ddlgwsub.SelectedValue.Trim();
            string shen = ddlSheng.SelectedValue.Trim();
            string shensub = ddlShi.SelectedValue.Trim();
            string zone = ddlzone.SelectedValue.Trim();
            string edu = ddledu.SelectedValue.Trim();
            string sex = ddlsex.SelectedValue.Trim();

            if (key != "")
                whe = " and (title like '%" + key + "%' or keys like '%" + key + "%') ";

            if (cbh != "")
                whe = whe + " and cbh='" + cbh + "' ";

            if (gw != "")
                whe = whe + " and cate='" + gw + "' ";

            if (gws != "")
            {
                if (gw != gws)
                    whe = whe + " and cate_sub='" + gws + "' ";
            }

            if (shen != "")
                whe = whe + " and area='" + shen + "' ";

            if (shensub != "")
            {
                if (shen != shensub)
                    whe = whe + " and area_sub='" + shensub + "' ";
            }


            if (zone != "")
            {
                if (zone != "0")
                    whe = whe + " and zone='" + zone + "' ";
            }

            if (edu != "")
            {
                whe = whe + " and edu='" + edu + "' ";
            }

            if (sex != "")
            {
                whe = whe + " and sex='" + sex + "' ";
            }
            //string person = ddlperson.SelectedText;
            //string dts1 = date1.Text;
            //string dts2 = date2.Text;

            //   if (comp != "")
            ///      whe = whe + " and cname='" + comp + "'";

            //if (person != "")
            //    whe = whe + " and user_name='" + person + "'";

            // if (dts1 != ""&dts2!="")
            //    whe = whe + " and pdtime>='" + 
            //        dts1 + "' and pdtime<='" + dts2 + "'";


            //   DataTable dt = BLL.Bllbase.get_sql(tab, whe, " group by pname,pdtime ", " order by COUNT(sid) desc");

            BindGrid();


        }

    

        }




    
}